<template>
    <div class="menu-tags-main">
        <div class="scroll-body">
            <i class="el-icon-arrow-left box-l-arrow" @click="clickTagNavListArrow('left')"></i>
            <i class="el-icon-arrow-right box-r-arrow" @click="clickTagNavListArrow('right')"></i>
            <div class="box-close">
                <i class="el-icon-close"></i>
                <div class="close-option">
                    <p class="close-all" @click="closeTagMenu('all')">关闭所有</p>
                    <p class="close-other" @click="closeTagMenu('other')">关闭其它</p>
                </div>
            </div>
            <div class="scroll-main">
                <div class="box-scroll"
                    :style="{ width: this.$store.state.menu.menuData.tagNavList.width + 'px', left: this.$store.state.menu.menuData.tagNavList.left + 'px' }">
                    <div class="box-tag" v-for="(item, index) in this.$store.state.menu.menuData.tagNavList.data"
                        :key="item.id" @click="selectTagNavList(item, index)">
                        <div :class="item.id == activeId ? 'round round-bag' : 'round'"></div>
                        <span>{{ item.name }}</span>
                        <i class="el-icon-close del-tag-btn"
                            :style="index > 0 && item.id == activeId ? 'visibility: visible' : ''"
                            @click="delTagNavList(item)"></i>
                        <div class="line"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
  
<script>
export default {
    name: "x-menu-tags",
    data() {
        return {
        };
    },
    methods: {
        delTagNavList(menuInfo) {
            this.$store.commit('delTagNavList', menuInfo);
        },
        selectTagNavList(menuInfo, index) {
            this.$store.commit('selectTagNavList', {
                menuInfo: menuInfo,
                clickMenuIsOpenSideMenu: this.$store.state.theme.interface.clickMenuIsOpenSideMenu
            });
            this.$store.commit('setTagNavListDomLeft', index);
        },
        clickTagNavListArrow(type) {
            this.$store.commit('clickTagNavListArrow', type);
        },
        closeTagMenu(type) {
            this.$store.commit('closeTagMenu', type);
        }
    },
    created() {
        this.$nextTick(() => {
            let scrollMainWidth = document.querySelector('.scroll-main').offsetWidth;
            this.$store.commit('setTagNavListScrollMainWidth', scrollMainWidth);
        });
    },
    computed: {
        activeId() {
            return this.$store.state.menu.menuData.tagNavList.activeId;
        }
    },
    watch: {
        '$store.state.menu.menuData.tagNavList.activeId': {
            handler: function (newValue, oldValue) {
                let tagMenu = this.$store.state.menu.menuData.tagNavList.data.find(item => item.id === newValue);
                this.$router.push(`/views${tagMenu.path}`);
            },
            deep: true
        }
    }
}
</script>

<style scoped lang="less">
.menu-tags-main {
    width: 100%;
    height: 43px;
    cursor: pointer;
    transition: all 0.3s;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;

    .scroll-body {
        width: 100%;
        height: 43px;
        background-color: #FFFFFF;
        border: 1px solid #F3F3F3;
        box-sizing: border-box;
        position: relative;

        .box-l-arrow {
            width: 34px;
            font-weight: 700;
            text-align: center;
            line-height: 41px;
            position: absolute;
            top: 0px;
            left: 0px;
            border-right: 1px solid #F3F3F3;
            background-color: #FFFFFF;
            box-sizing: border-box;
            z-index: 2;

            &:hover {
                transition: all 0.1s;
                background-color: #F5F5F5;
                color: #2DAAF6;
            }
        }

        .box-r-arrow {
            width: 34px;
            font-weight: 700;
            text-align: center;
            line-height: 41px;
            position: absolute;
            top: 0px;
            right: 33px;
            border-left: 1px solid #F3F3F3;
            background-color: #FFFFFF;
            box-sizing: border-box;
            z-index: 2;

            &:hover {
                transition: all 0.1s;
                background-color: #F5F5F5;
                color: #2DAAF6;
            }
        }

        .box-close {
            width: 34px;
            font-weight: 700;
            text-align: center;
            line-height: 40px;
            position: absolute;
            top: 0px;
            right: 0px;
            border: 1px solid #F3F3F3;
            box-sizing: border-box;
            background-color: #FFFFFF;
            z-index: 2;

            &:hover {
                transition: all 0.1s;
                background-color: #F5F5F5;
                color: #2DAAF6;
            }

            &:hover>.close-option {
                height: 86px;
            }

            .close-option {
                width: 80px;
                height: 0px;
                background-color: #FFFFFF;
                position: absolute;
                top: 45px;
                right: 5px;
                overflow: hidden;
                align-items: center;
                text-align: center;
                transition: all 0.3s;
                transition-timing-function: ease;
                border-radius: 5px;
                z-index: 99;
                box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.6), -2px -2px 2px rgba(255, 255, 255, 1);

                p {
                    font-weight: 400;
                    font-size: 12px;
                    line-height: 24px;
                    color: var(--fondGrey);

                    &:hover {
                        color: #2D8CF0;
                        text-decoration: underline;
                    }

                    &:hover>i {
                        color: red;
                    }
                }

                .close-all {
                    margin-top: 15px;
                }

                .close-other {
                    margin-bottom: 15px;
                }
            }
        }

        .scroll-main {
            width: calc(100% - 102px);
            height: 45px;
            position: absolute;
            top: 0px;
            left: 34px;
            overflow: hidden;

            .box-scroll {
                width: 100%;
                height: 42px;
                line-height: 42px;
                display: flex;
                align-items: center;
                justify-content: left;
                box-sizing: border-box;
                position: absolute;
                transition: all 0.3s;

                .box-tag {
                    padding: 0 10px;
                    display: flex;
                    align-items: center;
                    box-sizing: border-box;

                    &:hover {
                        transition: all 0.1s;
                        box-sizing: border-box;
                        border-radius: 5px;
                        box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.6), -2px -2px 2px rgba(255, 255, 255, 1);
                    }

                    .del-tag-btn {
                        visibility: hidden;
                        position: relative;
                        top: -15px;
                        right: -10px;
                    }

                    &:hover .del-tag-btn {
                        visibility: visible;
                    }

                    .round {
                        width: 10px;
                        height: 10px;
                        background-color: #E8EAEC;
                        border-radius: 50%;
                    }

                    .round-bag {
                        background-color: #2D8CF0;
                    }

                    span {
                        white-space: nowrap;
                        margin: 0 10px;
                        font-size: 12px;
                    }



                    i {
                        font-size: 14px;
                        margin-top: 2px;
                        margin-left: -2px;
                    }

                    i:hover {
                        color: #ED1C24;
                    }

                    .line {
                        height: 30px;
                        border-right: 1px solid #F3F3F3;
                        position: relative;
                        right: -10px;
                    }
                }
            }
        }
    }
}
</style>